<?php
function perform_insert_post($submit_name, $table_name, $field_list) {
  // echo $table_name;
  if(isset($_POST[$submit_name])) {
    foreach($field_list as $field) {
      if(isset($_POST[$field])) {
        $insert_fields[$field] = "'".$_POST[$field]."'";
      }
    }
    return db_insert($table_name, $insert_fields);
  } else {
    return -1;
  }
}

function perform_update_post($submit_name, $table_name, $update_field_list, 
  $id_field_name="id") {
  if(isset($_POST[$submit_name])&&isset($_POST[$id_field_name])) {
    foreach($update_field_list as $field) {
      if(isset($_POST[$field])) {
        $update_fields[$field] = "'".$_POST[$field]."'";
      }
    }
    db_update($table_name, $update_fields, $_POST[$id_field_name], 
      $id_field_name);
      return 1;
  }
  return -1;
}

function perform_delete_post($post_name, $table_name, $id_field_name = "id") {
  if(isset($_POST[$post_name])) {
    db_delete($table_name, $_POST[$post_name], $id_field_name);
    return 1;
  }
  return -1;
}
?>